﻿namespace Snipps.Validators
{
    using System;

    using FluentValidation;

    using Snipps.Langs;
    using Snipps.ViewModels.Pages;

    public class EditTagValidator : AbstractValidator<EditTagViewModel>
    {
        public EditTagValidator()
        {
            BaseRules();
        }

        public EditTagValidator(Func<string, bool> isTagExistFunc)
        {
            BaseRules();

            RuleFor(x => x.TagName).Must(t => !isTagExistFunc(t)).WithMessage(Lang.ValidationTagExists);
        }

        private void BaseRules()
        {
            RuleFor(x => x.TagName).NotEmpty().WithMessage(Lang.ValidationTagEmpty);
        }
    }
}